home *** CD-ROM | disk | FTP | other *** search
-
- /* File : getimage.c */
- /* Entered by : A. Wayner */
- # include <graphics.h>
- # include <stdlib.h>
- # include <alloc.h>
-
- main()
- {
- int graphdriver = DETECT, graphmode;
- char far *image;
- char buffer[80];
- unsigned numbytes;
-
- /* Detect adapter type and initialize */
- /* graphics system */
- initgraph( &graphdriver, &graphmode, "\\turboc" );
-
- /* Draw some graphical objects to save */
- setfillstyle( SOLID_FILL, LIGHTCYAN );
- bar( 50, 50, 90, 90 );
- setcolor( LIGHTMAGENTA );
- ellipse( 80, 80, 0, 360, 40, 40 );
-
- /* Determine storage needed for image */
- numbytes = (unsigned int ) imagesize( 0,0,50,50 );
-
- sprintf( buffer,
- "To save 51 x 51 image using getimage, we need %u bytes of memory.",
- numbytes );
-
- outtextxy( 10, 10, buffer );
-
- /* Allocate buffer for image */
- if( (image = (char far *) malloc (numbytes) ) == (char far * ) NULL )
- {
- closegraph();
- printf("Not enough memory for image storage \n");
- exit( 0 );
- }
-
- getimage( 50, 50, 100, 100, image ); /* save the image */
- outtextxy( 10, getmaxy()-50,"Image saved. Hit any key to continue");
- getch();
-
- /* Now clear screen and draw saved */
- /* image at several screen locations */
- cleardevice();
- setbkcolor( CYAN ); /* Change the background color */
- outtextxy( 10, 10,"Demonstrating getimage and putimage");
-
- putimage(80, 80, image, OR_PUT);
- putimage(150, 20, image, COPY_PUT);
- putimage(300,200,image, NOT_PUT );
-
-
- outtextxy( 10, getmaxy() - 30, "Press any key to exit");
-
- getch();
- closegraph();
- }
-
-